package org.vsb.chmireader.hibernate.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.vsb.chmireader.hibernate.entity.ChmiRecord;
import org.vsb.chmireader.log.LogUtils;

@Repository
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class, isolation = Isolation.READ_COMMITTED)
public class SaveChmiElements {
	static final Logger logger = LogUtils.getLogForMyClass();

	@Autowired
	private SessionFactory sessionFactory;

	public void saveElements(List<ChmiRecord> chmiRecordArray) {
		Session session = sessionFactory.getCurrentSession();
		for (ChmiRecord chR : chmiRecordArray)
			session.saveOrUpdate(chR);

	}

}
